package com.bootdo.app.controller;

import com.bootdo.app.utils.AppUtilXML;
import com.bootdo.app.utils.returnresponse.ServerResponse;
import com.bootdo.appsystem.domain.MessageDO;
import com.bootdo.appsystem.domain.ShouruDO;
import com.bootdo.appsystem.domain.UseraccountDO;
import com.bootdo.appsystem.service.MessageService;
import com.bootdo.common.controller.BaseController;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

/**
 * 【@author 】 @fan
 * 【@Email  】 mooncluyed@outlook.com
 * 【类解释  】
 * 【@Date   】 2018/6/9 0009
 **/
@Controller
@RequestMapping("/app/msage/")
public class AppMsageController extends BaseController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private MessageService messageService;


    @GetMapping("tousermsage")
    public String toUserMsage(){
        return "app/my/message";
    }

    @GetMapping("tomessagedetails")
    public String toMessageDetails(Integer id , Model model){
        MessageDO messageDO = messageService.get(id);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:dd:ss");
        String date = format.format(messageDO.getAddtime());
        model.addAttribute("date",date);
        model.addAttribute("message" , messageDO);
        return "app/my/messageDetail";
    }


    @PostMapping("msgusermsage")
    @ResponseBody
    public ServerResponse<PageUtils> msgUserMsage(@RequestParam Map<String, Object> params){
        Query query = new Query(params);
        UseraccountDO sessionCustomer = (UseraccountDO)this.getRequest().getSession().getAttribute(AppUtilXML.SESSION_CUSTOMER);
        query.put("uid" , sessionCustomer.getUid());
        List<MessageDO> messageDOList = messageService.list(query);
        int total = messageService.count(query);
        PageUtils pageUtils = new PageUtils(messageDOList, total);
        return ServerResponse.createBySuccess(pageUtils);
    }




}
